package hos.map.distance;

/**
 * <p>Title: LengthUnit </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2023-12-10 22:55
 */
public class LengthUnit {

    public static final LengthUnit Millimeter() {
        return new LengthUnit(1000.0);
    }

    public static final LengthUnit Centimeter() {
        return new LengthUnit(100.0);
    }

    public static final LengthUnit Meter() {
        return new LengthUnit(1.0);
    }

    public static final LengthUnit Kilometer() {
        return new LengthUnit(0.001);
    }

    public static final LengthUnit Mile() {
        return new LengthUnit(0.0006213712);
    }

    private final double scaleFactor;

    private LengthUnit(double scaleFactor) {
        this.scaleFactor = scaleFactor;
    }

    /**
     * 单位转换
     * @param unit 单位
     * @param value 要转行的数据
     */
    public double to(final LengthUnit unit, final double value) {
        if (unit.scaleFactor == scaleFactor) {
            return value;
        }
        // Convert to primary unit.
        final double primaryValue = value / scaleFactor;

        // Convert to destination unit.
        return primaryValue * unit.scaleFactor;
    }
}
